package com.gl.saasservice.home.service;

import com.gl.framework.web.response.Result;
import com.gl.saasservice.repository.DepartmentHierarchyRepository;
import com.gl.saasservice.repository.QYUserRepository;
import com.gl.saasservice.repository.UserRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class HomeService {
    private static final Logger log= LoggerFactory.getLogger(HomeService.class);

    @Autowired
    private DepartmentHierarchyRepository departmentHierarchyRepository;
    @Autowired
    private QYUserRepository qYUserRepository;
    @Autowired
    private UserRepository userRepository;


    public Result page(String token){
        log.info("HomeService page  token = {}",token);

        //显示基本数据：平台创建的机构数量，企业端用户总数，APP注册用户总数

        //平台创建的机构数量
        long hierarchyNum = departmentHierarchyRepository.count();

        //企业端用户总数 status  0未激活 1已激活 2已离职
        List<Short> list = new ArrayList();
        list.add((short)0);
        list.add((short)1);
        int userNum = qYUserRepository.countByStatusIn(list);

        //APP注册用户总数 status 状态：0禁用 1启用 2已删除
        List<Integer> appList = new ArrayList();
        appList.add(0);
        appList.add(1);
        int appUserNum = userRepository.countByStatusIn(appList);

        Map<String,Object> map =new HashMap<>();

        map.put("hierarchyNum",hierarchyNum);
        map.put("userNum",userNum);
        map.put("appUserNum",appUserNum);

        return Result.success(map);
    }

}
